import axios from './axios.js';

export function getGoodsList() {
    return axios.get('/goods/list');
}

export function getLikeList(page) {
    return axios.get(`/like_list?page=${page}`);
}
// 获取topBar的数据
export function getTopBarList() {
    return axios.get(`/getTopBarList`);
}
// 获取轮播图数据
export function getSwiperList() {
    return axios.get(`/getSwiperList`);
}
// /api
export function getIndexList() {
    return axios.get(`/index_list/0/data/1`);
}
// 获取活动页的数据
export function getActivityList(page) {
    return axios.get(`/getActivityList?page=${page}`);
}

// 修改密码接口
export function recovery(phone, pwd) {
    return axios.post('/recovery', { phone, pwd });
}
// 获取短信验证码的接口
export function getCode(phone) {
    return axios.post('/code', { phone });
}
// 验证码验证成功的登录接口
export function addUser(phone) {
    return axios.post('/addUser', { phone });
}
// 注册接口
export function register(phone, pwd) {
    return axios.post('/register', { phone, pwd });
}
// 账号密码登录接口
export function login(userTel, userPwd) {
    return axios.post('/login', { userTel, userPwd });
}
// 查询用户是否存在
export function selectUser(phone) {
    return axios.post('/selectUser', { phone });
}

// 查询商品数据接口
export function getGoodsShopList(searchName, orderBy, currentIndex) {
    console.log(searchName, orderBy);
    return axios.get(`/goods/shopList/?searchName=${searchName}&zh=${orderBy}&currentIndex=${currentIndex}`);
}

// 获取商品详情
export function getGoodsDetail(id) {
    return axios.get(`/goods/id/?id=${id}`);
}

// 加入购物车
export function addCart(goodsId) {
    console.log(goodsId);
    return axios.post('/addCart', { goodsId });
}

// 获取购物车数据
export function selectCart() {
    return axios.post('/selectCart');
}

// 改变购物车商品数量
export function updateNum(id, num) {
    return axios.post('/updateNum', { id, num });
}
// 删除购物车商品
export function deleteCart(arrId) {
    return axios.post('/deleteCart', { arrId });
}

// 生成订单
export function addOrder(arr) {
    console.log(arr);
    return axios.post('/addOrder', { arr });
}

// 查询地址的接口
export function selectAddress() {
    return axios.post('/selectAddress');
}
// 新增收货地址
export function addAddress(data) {
    return axios.post('/addAddress', { ...data });
}
// 修改收货地址
export function updateAddress(data) {
    return axios.post('/updateAddress', { ...data });
}
// 删除收货地址
export function deleteAddress(id) {
    return axios.post('/deleteAddress', { id });
}

// 查询订单
export function selectOrder(orderId) {
    return axios.post('selectOrder', { orderId });
}

// 提交订单
export function submitOrder(orderId, shopArr) {
    return axios.post('/submitOrder', { orderId, shopArr });
}

// 支付接口
export function payment(dataOrder) {
    return axios.post('/payment', dataOrder);
}

// 支付成功接口
export function successPayment(datas) {
    return axios.post('api/successPayment', datas);
}
